<template>
  <div>
    <div>
      <PageTools>
        <!-- <template slot="right"> -->
        <!-- <template v-slot:right> -->
        <template #right>
          <el-button
            size="small"
            type="primary"
            @click="addPer('', 1)"
          >添加权限</el-button>
        </template>
      </PageTools>
      <!-- 表格 -->
      <el-card>
        <el-table
          :data="tableData"
          style="width: 100%; margin-bottom: 20px"
          row-key="id"
          border
          default-expand-all
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <el-table-column prop="name" label="名称" sortable />
          <el-table-column prop="code" label="标识" sortable />
          <el-table-column prop="description" label="描述" />
          <el-table-column fixed="right" label="操作" width="180">
            <template
              #default="scoped"
            >==>{{ scoped.row.type }}
              <el-button
                v-if="scoped.row.type === 1"
                type="text"
                size="small"
                @click="addPer(scoped.row.id, 2)"
              >
                添加
              </el-button>
              <!-- <el-button type="text" size="small"> 添加 </el-button> -->
              <el-button
                v-arrow="'edit1'"
                type="text"
                size="small"
                @click="editHandle(scoped.row)"
              >
                编辑
              </el-button>
              <el-button type="text" size="small"> 删除 </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 对话框 -->
    <el-dialog :visible.sync="showDialog" title="弹层标题" @close="close">
      <perDia
        v-if="showDialog"
        :is-edit="isEdit"
        :row="row"
        :pid="pid"
        :type="type"
        :show-dialog.sync="showDialog"
        @success="success"
      />
    </el-dialog>
  </div>
</template>

<script>
import { toDo2 } from '@/utils'
import { getPermissionList } from '@/api/permission'
import perDia from './components/perDia.vue'
export default {
  name: '',
  components: {
    perDia
  },
  data() {
    return {
      tableData: [],
      showDialog: false, // 是否显示弹层
      pid: '',
      type: '',
      isEdit: false,
      row: {}
    }
  },

  computed: {},
  created() {
    this.loadPer()
  },
  methods: {
    editHandle(row) {
      console.log(row, 999)
      this.showDialog = true
      this.isEdit = true
      this.row = row
    },
    addPer(pid, type) {
      this.isEdit = false
      this.showDialog = true
      this.pid = pid
      this.type = type
    },
    async loadPer() {
      const res = await getPermissionList()
      // console.log(res, 7)
      this.tableData = toDo2(res.data)
    },
    close() {}, //     Dialog 关闭的回调
    success() {
      this.showDialog = false
      this.loadPer()
    }
  }
}
</script>
<style lang="less" scoped></style>
